<template>
  <div>
      <el-tree
  :data="permiss"
  show-checkbox
  default-expand-all
  node-key="id"
  ref="tree"
  highlight-current
  :default-checked-keys	="defaultchecked"
  :props="{label: 'name'}">
</el-tree>
<el-button type="primary" @click="save()">保存数据</el-button>
  </div>
</template>

<script>
export default {
    name: 'RolePermission',
    data(){
        return{
            permiss:[],
            defaultchecked:[],
            form:{
                roleId: 0,
                permissionId: []
            }
        }
    },
    created(){
        this.form.roleId = this.$route.query.id
        this.getData()
        this.getPermiss()
    },
    methods:{
        getPermiss(){
            this.axios.get('/ums-role-permission/get-permiss',response =>{
                this.permiss = response.obj
            })
        },
        getData(){
            this.axios.get('/ums-role-permission/getByRoleId',response =>{
                this.form.id = response.obj.id
                this.defaultchecked = response.obj.permissionId.split(',').map(Number)
            },{roleId:this.form.roleId})
        },
        save(){
            this.form.permissionId = this.$refs.tree.getCheckedKeys()
            this.axios.post('/ums-role-permission/save',response => {
                this.$router.push('/role')
            },this.form)
        }
    }
}
</script>

<style>

</style>